#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstdio>

using namespace std;
const int N = 4010;

bool g[N][N];
int d[N];
int q[N][3], idx;
int n, m;
int select()
{
    int res = 0x3f3f3f3f;
    for (int i = 1; i < idx; i++)
        res = min(d[q[i][0]] + d[q[i][1]] + d[q[i][2]] - 6, res);
    if (res == 0x3f3f3f3f) return -1;
    return res;
}
int main()
{
    scanf("%d%d", &n, &m);

    while (m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if (!g[a][b])
        {
            g[a][b] = true, g[b][a] = true;
            d[a] ++, d[b] ++;
            for (int i = 1; i <= n; i++)
            {
                if (g[b][i] && g[i][a])
                {
                    q[idx][0] = a;
                    q[idx][1] = b;
                    q[idx ++][2] = i;
                }
            }
        }
    }
    printf("%d", select());
    return 0;
}